package com.md.drcs.dicom.dao;

import com.md.common.utils.dao.MyMapper;
import com.md.drcs.dicom.entity.StudyHelpEntity;
import com.md.drcs.dicom.req.StudyHelpQueryReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface StudyHelpDao extends MyMapper<StudyHelpEntity> {

    @Select("select * from t_study_help where from_user_id = #{doctorId} order by id desc, `status` asc")
    List<StudyHelpEntity> findByFromDoctor(StudyHelpQueryReq req);

    @Select("select * from t_study_help where to_user_id = #{doctorId} order by id desc, `status` asc")
    List<StudyHelpEntity> findByToDoctor(StudyHelpQueryReq req);

    @Update("update t_study_help set `status` = #{status}, handle_time = now() where id = #{id}")
    void updateStatus(@Param("id") Integer id, @Param("status") Integer status);

    @Select("select count(0) from t_study_help where `status` = 0 and to_user_id = #{userId}")
    Integer getUnhandleCount(Integer userId);
}
